<?php

/**
 * contenido actions.
 *
 * @package    quieromascota
 * @subpackage contenido
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class contenidoActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    /* $this->noticias = Doctrine::getTable('Noticia')
      ->createQuery('a')
	  ->limit(5)
      ->execute();*/
     
      
      /* Codigo util para matar la sesion de manera forzada, solo activar para pruebas*/
      /*
    $this->getUser()->setAuthenticated(false);

    $this->getUser()->clearCredentials();

    if ($this->getUser()->hasCredential('Usuario')) $this->getUser()->getAttributeHolder()->removeNamespace('Usuario');

    if ($this->getUser()->hasCredential('Asesor')) $this->getUser()->getAttributeHolder()->removeNamespace('Asesor');

    if ($this->getUser()->hasCredential('Admin')) $this->getUser()->getAttributeHolder()->removeNamespace('Admin');

    $this->getUser()->getAttributeHolder()->remove('id_usuario');
    $this->getUser()->getAttributeHolder()->remove('nombre');

    $this->getUser()->shutdown();*/
  }
  
  public function executeNosotros(sfWebRequest $request)
  {
      
       $this->contenido = Doctrine::getTable('contenido')
        ->createQuery('p')
        ->execute();
  
  }
  
  public function executeFaq(sfWebRequest $request)
  {
      
      $this->contenido = Doctrine::getTable('contenido')
        ->createQuery('p')
        ->execute();
      
  }
  
  public function executeUbicacion(sfWebRequest $request)
  {
      
      $this->contenido = Doctrine::getTable('contenido')
        ->createQuery('p')
        ->execute();
  	
  } 
  
  public function executeContacto(sfWebRequest $request)
  {
    //$this->usuario = Doctrine::getTable('Usuario')->find(array($this->getUser()->getAttribute('id_usuario')));
  }
  
  public function executeSietepasos(sfWebRequest $request)
  {
    
  }
  
  public function executeEnviarMail(sfWebRequest $request)
  {        
    // send an email to the affiliate
    $transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
  		->setUsername('toyomotorenvios@gmail.com')
  		->setPassword('QOIzYaaab');

    $sub = utf8_encode('Contacto');
    $from = utf8_encode('AUTOMOTRIZ TOYOMOTOR');

    $mailer = Swift_Mailer::newInstance($transport);

    $message = Swift_Message::newInstance()
	->setCharset('utf-8')

	//Give the message a subject
	->setSubject($sub)

	//Set the From address with an associative array
	->setFrom(array($request->getParameter('email')));

	//Set the To addresses with an associative array
      /* Autor: Ing. Roberto Hernández De La Luz
       * Fecha: 12/09/2011
       * Codigo agregado para enviar al departamento adecuado*/
      
      switch($request->getParameter('departamento')):
          case 0:
              $message->setTo(array('repuestos@toyomotor.com' => $from));
              break;
          case 1:
              $message->setTo(array('ventas@toyomotor.com' => $from));
              break;
          case 2:
              $message->setTo(array('servicio@toyomotor.com' => $from));
              break;
          case 3:
              //Este correo debe cambiarse cuando se defina el email correcto
              $message->setTo(array('relacionesconclientes@toyomotor.com' => $from));
              break;
          case 4:
              $message->setTo(array('relacionesconclientes@toyomotor.com' => $from));
              break;
      endswitch;

        //Give it a body
	$message->setBody('Se ha recibido un mensaje de '.$request->getParameter('nombre').',
            con email '.$request->getParameter('email').'
                y tel&eacute;fono '.$request->getParameter('telefono').' '.$request->getParameter('telefono').'<br/> <br/>
            Comentario:<br/>
            '.$request->getParameter('comentario'), 'text/html');

	//Send the message
	$result = $mailer->send($message);
 
    $this->redirect('contenido/contacto?enviado=1');
  }
}
